package com.jf3q.front.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jf3q.common.domain.EduChapter;
import com.jf3q.common.domain.EduCourse;
import com.jf3q.common.domain.EduTeacher;
import com.jf3q.common.domain.EduVideo;
import com.jf3q.common.service.impl.EduChapterServiceImpl;
import com.jf3q.common.service.impl.EduCourseServiceImpl;
import com.jf3q.common.service.impl.EduTeacherServiceImpl;
import com.jf3q.common.service.impl.EduVideoServiceImpl;
import com.jf3q.common.vo.CourseWebVo;
import com.jf3q.common.vo.ResultVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/details")
@Tag(name = "详情接口")
public class DetailsController {
    @Autowired
    EduCourseServiceImpl courseService;
    @Autowired
    EduTeacherServiceImpl teacherService;
    @Autowired
    EduChapterServiceImpl chapterService;
    @Autowired
    EduVideoServiceImpl videoService;



    @GetMapping("/course")
    @Operation(summary = "课程详情")
    public ResultVo course(String id){
        CourseWebVo courseWebVo=courseService.courseById(id);

        LambdaQueryWrapper<EduChapter> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EduChapter::getCourseId, id);
        queryWrapper.orderByAsc(EduChapter::getSort);
        List<EduChapter> list = chapterService.list(queryWrapper);
        for (EduChapter chapter : list) {
            LambdaQueryWrapper<EduVideo> queryWrapperV = new LambdaQueryWrapper<>();
            queryWrapperV.eq(EduVideo::getChapterId, chapter.getId());
            queryWrapperV.orderByAsc(EduVideo::getSort);
            chapter.setVideos(videoService.list(queryWrapperV));
        }
        courseWebVo.setChapterVideoList(list);
        return ResultVo.success("",courseWebVo);
    }

    @GetMapping("/teacher")
    @Operation(summary = "教师详情")
    public ResultVo teacherList(String id){
        EduTeacher teacher=teacherService.getById(id);

        List<EduCourse> list=courseService.courseListById(id);
        teacher.setCourseList(list);

        return ResultVo.success("",teacher);
    }


}
